package com.ls.util;

/**
 * @author ls
 * @date 2021/1/5
 **/
public class RedisKeyUtil {

    private RedisKeyUtil() {
    }

    /**
     * redisKey前缀
     * 分隔符
     */
    private static final String SPLIT = ":";
    /**
     * 实体被点赞前缀 帖子,评论,回复
     */
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    /**
     * 用户被点赞
     */
    private static final String PREFIX_USER_LIKE = "like:user";
    /**
     * 关注
     */
    private static final String PREFIX_FOLLOWEE = "followee";
    /**
     * 粉丝
     */
    private static final String PREFIX_FOLLOWER = "follower";
    /**
     * 验证码
     */
    private static final String PREFIX_KAPTCHA = "kaptcha";
    /**
     * 登录凭证
     */
    private static final String PREFIX_TICKET = "ticket";

    /**
     * 用户
     */
    private static final String PREFIX_USER = "user";

    /**
     * 帖子
     */
    private static final String PREFIX_POST = "post";
    /**
     * 独立访客
     */
    private static final String PREFIX_UV = "uv";
    /**
     * 日活跃用户
     */
    private static final String PREFIX_DAU = "dau";


    /**
     * 某个实体的赞
     * like:entity:entityType:entityId -> set(userId)
     *
     * @param entityType
     * @param entityId
     * @return
     */
    public static String getEntityLikeKey(int entityType, int entityId) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 用户的获得的赞
     * like:user:userId -> int
     *
     * @param userId
     * @return
     */
    public static String getUserLikeKey(int userId) {
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    /**
     * 某个用户关注的实体
     * followee:userId:entityType  -> zset(entityId, now)
     *
     * @param userId
     * @param entityType
     * @return
     */
    public static String getFolloweeKey(int userId, int entityType) {
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    /**
     * 某个实体的粉丝
     * follower:entityType:entityId  -> zset(userId, now)
     *
     * @param entityType
     * @param entityId
     * @return
     */
    public static String getFollowerKey(int entityType, int entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 返回登录验证码 key
     *
     * @param owner 验证码拥有者 (用户临时凭证)
     * @return 登录验证码
     */
    public static String getKaptchaKey(String owner) {
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

    /**
     * 返回登录凭证 key
     *
     * @param ticket 登录凭证
     * @return 登录凭证 key
     */
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    /**
     * 返回用户 key
     *
     * @param userId 用户id
     * @return 用户 key
     */
    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

    /**
     * 功能描述: <br>
     * 单日UV
     *
     * @param date
     * @return {@link String}
     * @author ls
     * @date 2021/8/23 23:57
     */
    public static String getUVKey(String date) {
        return PREFIX_UV + SPLIT + date;
    }

    /**
     * 功能描述: <br>
     * 日期区间UV
     *
     * @param start
     * @param end
     * @return {@link String}
     * @author ls
     * @date 2021/8/23 23:57
     */
    public static String getUVKey(String start, String end) {
        return PREFIX_UV + SPLIT + start + SPLIT + end;
    }

    /**
     * 功能描述: <br>
     * 单日DAU
     *
     * @param date
     * @return {@link String}
     * @author ls
     * @date 2021/8/24 0:00
     */
    public static String getDAUKey(String date) {
        return PREFIX_DAU + SPLIT + date;
    }

    /**
     * 功能描述: <br>
     * 日期区间DAU
     *
     * @param start
     * @param end
     * @return {@link String}
     * @author ls
     * @date 2021/8/24 0:00
     */
    public static String getDAUKey(String start, String end) {
        return PREFIX_DAU + SPLIT + start + SPLIT + end;
    }

    /**
     * 功能描述: <br>
     * 记录变化的帖子
     *
     * @return {@link String}
     * @author ls
     * @date 2021/8/24 22:29
     */
    public static String getPostScoreKey() {
        return PREFIX_POST + SPLIT + "score";
    }

}
